package com.stockz.ui.swing.charting.util;

import java.util.List;

import com.stockz.core.manager.BarManager;
import com.stockz.core.model.Bar;
import com.stockz.core.util.SpringUtil;
import com.stockz.ui.swing.charting.display.Displayable;
import com.stockz.ui.swing.charting.view.StockChartPanel;
import com.stockz.ui.swing.charting.view.StockChartPanelState;

public class RefreshChartingDataUtil {
	
	private static BarManager barManager;
	
	public static void refreshChartingData(StockChartPanel stockChartPanel) {
		StockChartPanelState chartingPanelState = stockChartPanel.getStockChartPanelState();
		if(barManager == null){
			barManager = SpringUtil.getApplicationContext().getBean(BarManager.class);
		}
		List<Bar> barList = barManager.getBarList(chartingPanelState.getScrip().getCode());
		chartingPanelState.getBarList().clear();
		chartingPanelState.getBarList().addAll(barList);
		chartingPanelState.getBackupBarList().clear();
		chartingPanelState.getBackupBarList().addAll(barList);
		chartingPanelState.getShapeSet().clear();
		stockChartPanel.getView().setTitle(chartingPanelState.getScrip().getName()+"("+chartingPanelState.getScrip().getCode()+")");
		for(Displayable indicatorDisplay : chartingPanelState.getDisplayableSet()){
			indicatorDisplay.refreshValues();
		}
		//SetStockChartPanelSizeUtil.setStockChartPanelSize(stockChartPanel);
		//SetStockChartViewPortUtil.setStockChartViewPort(stockChartPanel);
		ChangeTimeUnitUtil.changeTimeUnit(stockChartPanel);
	}
}
